if (USE_PSI3)

  # look for executable in the path given by the cmake variable
  if (PSI3_DIR)
    find_file(PSI3_EXE
              psi3
              PATHS ${PSI3_DIR}/bin
              NO_DEFAULT_PATH
             )
  endif (PSI3_DIR)

  # if not found, look for executable in the path given by the environment variable
  if (NOT PSI3_EXE)
    unset(PSI3_DIR)
    unset(PSI3_DIR CACHE)
    find_path(PSI3_DIR
              bin
              PATHS $ENV{PSI3_DIR}
              NO_DEFAULT_PATH
             )
    find_file(PSI3_EXE
              psi3
              PATHS ${PSI3_DIR}/bin
              NO_DEFAULT_PATH
             )
  endif (NOT PSI3_EXE)

  # error if we don't find the executable
  if (NOT PSI3_EXE)
    unset(PSI3_DIR)
    unset(PSI3_DIR CACHE)
    message(FATAL_ERROR "Could not find psi3 executable")
  endif (NOT PSI3_EXE)

  # find the libraries
  unset (PSI3_LIBS)
  #foreach (PSI3_LOOP_LIB libPSI_dpd libPSI_qt libPSI_chkpt libPSI_iwl libPSI_psio libPSI_ciomr libPSI_ipv1)
  foreach (PSI3_LOOP_LIB PSI_dpd PSI_qt PSI_chkpt PSI_iwl PSI_psio PSI_ciomr PSI_ipv1)
    find_library(PSI3_LOOP_LIB_FOUND
                 ${PSI3_LOOP_LIB}
                 PATHS ${PSI3_DIR}/lib
                 NO_DEFAULT_PATH
                )
    if (NOT PSI3_LOOP_LIB_FOUND)
      message(FATAL_ERROR "Could not find psi3 library ${PSI3_LOOP_LIB}")
    endif (NOT PSI3_LOOP_LIB_FOUND)
    set (PSI3_LIBS "${PSI3_LIBS};${PSI3_LOOP_LIB_FOUND}")
    unset (PSI3_LOOP_LIB_FOUND)
    unset (PSI3_LOOP_LIB_FOUND CACHE)
  endforeach (PSI3_LOOP_LIB)

  # find the include directory
  find_path(PSI3_INCLUDE
            psifiles.h
            PATHS ${PSI3_DIR}/include
            NO_DEFAULT_PATH
           )
  if (NOT PSI3_INCLUDE)
    message(FATAL_ERROR "Could not find psi3 include directory")
  endif (NOT PSI3_INCLUDE)

  # use the include directory
  include_directories(${PSI3_INCLUDE})

  # print out what was found
  message(STATUS "Using psi3 executable " ${PSI3_EXE})
  foreach (PSI3_LOOP_LIB ${PSI3_LIBS})
    message(STATUS "Using psi3 library " ${PSI3_LOOP_LIB})
  endforeach (PSI3_LOOP_LIB)

  unset (PSI3_LOOP_LIB)
  unset (PSI3_LOOP_LIB CACHE)

endif (USE_PSI3)
